-- get_user_data_ini
--
local import = import
---@type behavior_ret
local bret = import('bt/bt_plugin/behavior3/behavior_ret')
---@type api
local api = import("api/api")
---@type configer
local configer = import("base/configer")
---@type redis
local redis = import("game/func/redis")
local M = {
    name = "get_user_data_ini",
    type = "Action",
    desc = "获取用户ini",
    args = {
        { name = "section", type = "string?", desc = "区块" },
        { name = "key", type = "string?", desc = "键" },
        {
            name = "nType",
            type = "enum?",
            desc = "过期时间",
            options = {
                {
                    name = "日",
                    value = 1,
                },
                {
                    name = "周",
                    value = 2,
                },
                {
                    name = "无",
                    value = 0,
                },
                {
                    name = "半日",
                    value = 3,
                },
            },
        },
    },
    input = { "区块?", "键?" },
    output = { "输出结果/string" },
}

function M.run(node, env, section, key)
    -- node.args.str
    section = section or node.args.section
    key = key or node.args.key
    local nType = node.args.nType or 0
    local value
    if nType == 0 then
        value = configer.get_user_profile(section, key)
    elseif nType == 1 then
        value = redis.get_user_profile_today_four(section, key)
    elseif nType == 2 then
        value = redis.get_user_profile_to_monday(section, key)
    elseif nType == 3 then
        local hour = tonumber(os.date("%H"))
        if hour < 12 then
            hour = hour + 24
        end
        hour = hour - 12
        value = redis.get_user_profile_today_four(section, key, hour)
    end
    if not value or value == "" then
        return bret.FAIL
    end
    return bret.SUCCESS, value

end

return M
